% Class for Distribution Approximation
% Properties:
%   1. Information about each dimension
%      UnitName (Cell(n,1)); UnitLimit (Matrix(nx2));
%      UnitNode (Cell(n,1)); UnitNum (Vector(n)); 
%   2. Distribution Approximation
%      Dim (Integer); 
%      Node (Matrix (Dim x n)); IndNode (Matrix (Dim x n));
% Methods:
%   1. 

classdef DistAppClass
    properties
        UnitName
        UnitLimit
        UnitBreaks
        UnitNode
        UnitNum
        
        Dim
        Num
        Node
        IndNode
        
        State
    end
    methods 
        function DistApp=DistAppClass(UnitName,UnitType,UnitBreaks,UnitNode)
            Dim             =   length(UnitName);
            if (Dim~=length(UnitBreaks)) || (Dim~=length(UnitType)) || ...
               (Dim~=length(UnitNode)) 
                error('Dimension does not match!');
            end
            DistApp.Dim     =   Dim;
            DistApp.UnitName=   UnitName;
            % Node
            DistApp.UnitBreaks ...
                            =   UnitBreaks;
            DistApp.UnitNode=   UnitNode;
            DistApp.Node    =   gridmake(DistApp.UnitNode);
            
            % Dimension, Limits, Index Node and State
            DistApp.Num     =   size(DistApp.Node,1);
            UnitNum         =   zeros(Dim,1);
            UnitLimit       =   zeros(Dim,2);
            UnitIndNode     =   cell(Dim,1);
            UnitState       =   cell(Dim,1);
            for dd=1:Dim
                UnitNum(dd)     =   length(DistApp.UnitNode{dd});
                UnitLimit(dd,:) =   [min(UnitNode{dd}),max(UnitNode{dd})];
                UnitIndNode{dd} =   (1:1:UnitNum(dd))';
                switch UnitType{dd}
                    case 'Continuous'
                        UnitState{dd}   =   UnitNode{dd};
                    case 'Discrete'
                        UnitState{dd}   =   UnitIndNode{dd};
                end
            end
            
            DistApp.UnitNum =  UnitNum;
            DistApp.UnitLimit= UnitLimit;
            DistApp.IndNode =  gridmake(UnitIndNode);
            DistApp.State   =  gridmake(UnitState);
        end
    end
end